908C - New Year and Curling - CodeForces Solution


brute force geometry implementation math *1500

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define db double 
#define inf 0x3f3f3f3f
const db pi = acos(-1.0);
const int N = 1e4+10;
const int mod = 1e9+7;
const db eps = 1e-9;
int n,r;
db pp(int a,int b,db c,int e){
	db xx=(e*e-(a-b)*(a-b));
	return sqrt(xx)+c;
}
db y[N];
int x[N];
void solve(){
	cin>>n>>r;
	for(int i=1;i<=n;i++)cin>>x[i];
	y[1]=r*1.0;
	for(int i=2;i<=n;i++){
		int jj=i; y[i]=0.0;
		for(int j=i-1;j>0;j--){
			if(abs(x[i]-x[j])<=r*2){
					if(abs(x[i]-x[j])==r*2){
						y[i]=max(y[i],y[j]);
					}else y[i]=max(y[i],pp(x[i],x[j],y[j],r*2));jj=j;
			}
		}
		if(jj==i){
			y[i]=r;
		}
	}
	cout<<r<<" ";
	for(int i=2;i<=n;i++)printf("%.10lf ",y[i]);
}
signed main(){
	int __=1;
	//cin>>__;
	while(__--){
		solve();
	}
}


Comments

Submit
0 Comments
More Questions

1418A - Buying Torches
131C - The World is a Theatre
1696A - NIT orz
1178D - Prime Graph
1711D - Rain
534A - Exam
1472A - Cards for Friends
315A - Sereja and Bottles
1697C - awoo's Favorite Problem
165A - Supercentral Point
1493A - Anti-knapsack
1493B - Planet Lapituletti
747B - Mammoth's Genome Decoding
1591C - Minimize Distance
1182B - Plus from Picture
1674B - Dictionary
1426C - Increase and Copy
520C - DNA Alignment
767A - Snacktower
1365A - Matrix Game
714B - Filya and Homework
31A - Worms Evolution
1691A - Beat The Odds
433B - Kuriyama Mirai's Stones
892A - Greed
32A - Reconnaissance
1236D - Alice and the Doll
1207B - Square Filling
1676D - X-Sum
1679A - AvtoBus